//
//  LittleCarDatabase.m
//  我的小汽车
//
//  Created by 邹壮壮29 on 15-1-7.
//  Copyright (c) 2015年 蓝欧科技. All rights reserved.
//

#import "LittleCarDatabase.h"
#import <sqlite3.h>

static sqlite3 *dbPoint = nil;
@implementation LittleCarDatabase
+(sqlite3 *)openLittleCarDB{
    if (dbPoint) {
        return dbPoint;
    } else{
        NSFileManager *manager = [NSFileManager defaultManager];
        NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *path = [array lastObject];
        path = [NSString stringWithFormat:@"%@/LittleCar.db",path];
        //NSLog(@"%@",path);
        if (![manager fileExistsAtPath:path]) {
            NSString *source = [[NSBundle mainBundle] pathForResource:@"LittleCarDatabase" ofType:@"rdb"];
            [manager copyItemAtPath:source toPath:path error:nil];
        }
        sqlite3_open([path UTF8String], &dbPoint);
        return dbPoint;

    }
}
@end
